package com.nh.springdeal.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nh.springdeal.entity.Users;
import com.nh.springdeal.mapper.UsersMapper;
import com.nh.springdeal.req.UsersSaveReq;
import com.nh.springdeal.service.IUsersService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements IUsersService{

    @Resource
    private UsersMapper usersMapper;


    public void register(UsersSaveReq req){
        if (ObjectUtils.isEmpty(req.getId())){
            Users users = selectByUsername(req.getUsername());

        }
    }

    public Users selectByUsername(String username){
        QueryWrapper<Users> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(Users::getUsername,username);
        List<Users> usersEntityList = UsersMapper.selectList(wrapper);
        if (CollectionUtils.isEmpty(usersEntityList)){
            return null;
        }else {
            return usersEntityList.get(0);
        }



    }

}
